package com.example.smartcity_poverty.ui.AllService.SeeMovie.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_sm_show.*

/**
 * 详情页
 */
class SmShowActivity : AppCompatActivity() {

    // 接收电影id
    private val id by lazy { intent.getStringExtra("id")?.toInt() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_sm_show)
        title = "影片详情"


        // 获取影片详情
        coroutine() {
            api.getSmHomeListShow(id!!).apply {
                if (this.code == 200) {
                    runOnUiThread {
                        this.data?.let {
                            glide(url + it.cover, smShowImage)
                            smShowName.text = it.name
                            smShowNumber.text = "评分: ${it.score}"
                            smShowTime.text = "上映时间: ${it.playDate}"
                            smShowUserSize.text = "想看人数: ${it.likeNum}"
                        }
                    }
                } else runOnUiThread { this.msg?.show() }
            }
        }


        // 点击返回主页
        smShowOk.setOnClickListener { finish() }

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}